package com.mariusz.panels;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.BoxLayout;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Image;

import javax.swing.JTable;
import javax.swing.JList;
import javax.swing.AbstractListModel;

import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXList;
import org.jdesktop.swingx.JXPanel;

import javax.swing.JScrollPane;
import javax.swing.border.BevelBorder;
import org.jdesktop.swingx.JXImagePanel;
import java.awt.Toolkit;
import org.jdesktop.swingx.JXImageView;
import java.awt.Color;
import java.awt.SystemColor;
import org.jdesktop.swingx.JXButton;
import org.jdesktop.swingx.image.ColorTintFilter;
import org.jdesktop.swingx.image.FastBlurFilter;
import org.jdesktop.swingx.image.GaussianBlurFilter;
import org.jdesktop.swingx.image.StackBlurFilter;
import org.jdesktop.swingx.painter.AbstractPainter;

import com.mariusz.managers.DataManager;
import com.mariusz.managers.NavigationManager;
import com.mariusz.managers.RulesManager;
import com.mariusz.managers.NavigationManager.Screen;
import com.mariusz.ui.models.MessagesListModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URISyntaxException;
import java.util.List;

import javax.swing.JLabel;

public class StatusPanel extends JXPanel implements ActionListener {
	// private Image backgroundImage =
	// Toolkit.getDefaultToolkit().getImage(StatusPanel.class.getResource("/com/mariusz/resources/house_icon.jpg"));
	private JXButton btnRentiers;
	private JXButton btnManageProperties;
	private JXButton btnClose ;
	private JXButton btnLandlord;
	private JXList messages;
	public StatusPanel() {
		setForeground(SystemColor.controlText);
		setBackground(Color.WHITE);
		setLayout(null);

		btnRentiers = new JXButton("Tenants");
		btnRentiers.setBounds(521, 24, 137, 44);
		add(btnRentiers);
		btnRentiers.addActionListener(this);

		btnManageProperties = new JXButton();
		btnManageProperties.setText("Properties");
		btnManageProperties.setBounds(334, 24, 137, 44);
		add(btnManageProperties);
		btnManageProperties.addActionListener(this);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(6, 294, 652, 166);
		add(scrollPane);

		messages = new JXList();
		messages.setEnabled(true);
		scrollPane.setViewportView(messages);

		ResourceImagePanel imagePanel = new ResourceImagePanel("house_icon.jpg");
		imagePanel.setBounds(6, 24, 318, 264);
		add(imagePanel);
		
		JXButton btnAbouth = new JXButton("");
		btnAbouth.setEnabled(false);
		btnAbouth.setText("About");
		btnAbouth.setBounds(521, 79, 137, 44);
		add(btnAbouth);
		
		btnClose = new JXButton("Rentiers");
		btnClose.setText("Close");
		btnClose.setBounds(521, 134, 137, 44);
		btnClose.addActionListener(this);
		add(btnClose);
		
		btnLandlord = new JXButton("");
		btnLandlord.setText("Landlords ");
		btnLandlord.setBounds(334, 79, 137, 44);
		btnLandlord.addActionListener(this);
		add(btnLandlord);
		
		JLabel lblVersion = new JLabel("Version 0.6");
		lblVersion.setBounds(334, 269, 185, 14);
		add(lblVersion);
		
		JLabel lblAppName = new JLabel("Property Manager");
		lblAppName.setBounds(334, 249, 185, 14);
		add(lblAppName);

		fillMessages();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(btnRentiers)) {
			NavigationManager.getInstance().switchTo(Screen.RENTIER_LIST);
		} else if (e.getSource().equals(btnManageProperties)) {
			NavigationManager.getInstance().switchTo(Screen.PROPERTIES);
		} else if(e.getSource().equals(btnClose)){
	
		} else if(e.getSource().equals(btnLandlord)){
			NavigationManager.getInstance().switchTo(Screen.LANDLORDS);
		}

	}
	
	private void fillMessages(){
		List<String> messagesList = RulesManager.getInstance().processRules(DataManager.getInstance().getDataContainer());
		messages.setModel(new MessagesListModel(messagesList));
	}
	@Override
	public void show() {
		fillMessages();
		super.show();
	}
}
